home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / lib / check.pl < prev    next >
Encoding:
Text File  |  1997-10-13  |  3.3 KB  |  119 lines

  1. /*  $Id: check.pl,v 1.2 1997/10/13 10:07:57 jan Exp $
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Simple program consistency check predicates
  7. */
  8.  
  9. :- module(check,
  10.     [ check/0            % run all checks
  11.         , list_undefined/0        % list undefined predicates
  12.     , list_autoload/0        % list predicates that need autoloading
  13.     , list_redefined/0        % list redefinitions
  14.     ]).
  15.  
  16. :- style_check(+dollar).        % lock these predicates
  17.  
  18. %    check
  19. %    run all consistency checks of this module
  20.  
  21. check :-
  22.     format('PASS 1: Scanning for undefined predicates ...~n'),
  23.     list_undefined,
  24.     format('~nPASS 2: Scanning for redefined system and global predicates ...~n'),
  25.     list_redefined,
  26.     format('~nPASS 3: Scanning for predicates that need autoloading ...~n'),
  27.     list_autoload.
  28.  
  29. %    list_undefined
  30. %    List predicates names refered to  in  a  clause  body,  but  not
  31. %    defined.  This forms a "Quick and Dirty" alternative for a cross
  32. %    referencing tool (which I need to write someday).
  33.  
  34. list_undefined :-
  35.     $style_check(Old, Old), 
  36.     style_check(+dollar), 
  37.     list_undefined_, 
  38.     $style_check(_, Old).
  39.  
  40. list_undefined_ :-
  41.     predicate_property(Module:Head, undefined), 
  42.     \+ predicate_property(Module:Head, imported_from(_)), 
  43.     functor(Head, Functor, Arity), 
  44.     \+ $in_library(Functor, Arity),
  45.     \+ system_undefined(Module:Functor/Arity),
  46.     write_undefined(Module:Functor/Arity), 
  47.     fail.
  48. list_undefined_.
  49.  
  50. system_undefined(user:prolog_trace_interception/4).
  51.  
  52. write_undefined(user:Name/Arity) :- !, 
  53.     format('~w/~w~n', [Name, Arity]).
  54. write_undefined(Module:Name/Arity) :-
  55.     format('~w:~w/~w~n', [Module, Name, Arity]).
  56.  
  57. %    list_autoload/0
  58. %    Show predicates that need be linked via the autoload mechanism
  59.  
  60. list_autoload :-
  61.     $style_check(Old, Old), 
  62.     style_check(+dollar), 
  63.     please(autoload, OldAutoLoad, off),
  64.     list_autoload_, 
  65.     please(autoload, _, OldAutoLoad),
  66.     $style_check(_, Old).
  67.     
  68. list_autoload_ :-
  69.     predicate_property(Module:Head, undefined), 
  70.     \+ predicate_property(Module:Head, imported_from(_)), 
  71.     functor(Head, Functor, Arity), 
  72.     $in_library(Functor, Arity),
  73.     show_library(Module, Functor, Arity), 
  74.     fail.
  75. list_autoload_.
  76.  
  77. show_library(Module, Name, Arity) :-
  78.     $find_library(Module, Name, Arity, _LoadModule, Library),
  79.     (   Module == user
  80.     ->  format('~w/~w~t~30|~w~n', [Name, Arity, Library])
  81.     ;   format('~w:~w/~w~t~30|~w~n', [Module, Name, Arity, Library])
  82.     ).
  83.  
  84. %    list_redefined/0
  85. %    Show redefined system predicates
  86.  
  87. list_redefined :-
  88.     $style_check(Old, Old), 
  89.     style_check(+dollar), 
  90.     list_redefined_, 
  91.     $style_check(_, Old).
  92.     
  93. list_redefined_ :-
  94.     current_module(Module),
  95.     Module \== system,
  96.     current_predicate(_, Module:Head),
  97.     \+ predicate_property(Module:Head, imported_from(_)),
  98.     (   $default_module(Module, Super, Super),
  99.         $c_current_predicate(_, Super:Head),
  100.         $syspreds:$defined_predicate(Super:Head),
  101.         \+ predicate_property(Super:Head, (dynamic)),
  102.         \+ predicate_property(Super:Head, imported_from(Module)),
  103.         functor(Head, Functor, Arity)
  104.     ->  show_redefined(Module, Super, Functor, Arity)
  105.     ),
  106.     fail.
  107. list_redefined_.
  108.  
  109. show_redefined(user, system, F, A) :- !,
  110.     format('system predicate ~w/~w has been redefined globally.~n',
  111.                                 [F, A]).
  112. show_redefined(M, system, F, A) :-
  113.     format('system predicate ~w/~w has been redefined in module ~w.~n',
  114.                                 [F, A, M]).
  115. show_redefined(M, user, F, A) :- !,
  116.     format('global predicate ~w/~w has been redefined in module ~w.~n',
  117.                                 [F, A, M]).
  118.  
  119.